﻿-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Pwp_GetRecentPosts]
	-- Add the parameters for the stored procedure here
	@Skip int = 0, 
	@Take int = 5,
	@Total int output
AS
BEGIN
	SET NOCOUNT ON;
	
	SELECT @Total = COUNT(*) FROM PostInfo

	SELECT *
	FROM (
			SELECT ROW_NUMBER() OVER 
				(ORDER BY [t0].[DateCreated] DESC) AS [ROW_NUMBER],  *
				--[t0].[Id], [t0].[Title], [t0].[Description], [t0].[DateCreated], [t0].[Publish], [t0].[PostCategoryId]
			FROM [PostInfo] AS [t0]
		  ) AS [t1]
	WHERE 
		[t1].[ROW_NUMBER] BETWEEN @Skip + 1 AND @Skip + @Take
	ORDER BY 
		[t1].[ROW_NUMBER]

END